#include <iostream>
#include <math.h>
using namespace std;

int main(){
	int n,m;
	int inf=1e9+5;
	cin>>n>>m;
	int a[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			a[i][j] = inf;
		}
		a[i][i] = 0;
	}
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--;
		v--;
		a[u][v] = a[v][u] = min(w, a[u][v]);
	}
	
	
	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(a[i][j] > a[i][k]+a[k][j])
					a[i][j] = a[i][k]+a[k][j],a[j][i] = a[i][j];
	
	
	int mod = 998244354;
	for(int i=0;i<n;i++){
		int l=0;
		for(int j=0;j<n;j++){
			l = ((l+a[i][j]%mod)%mod);
//			l = (l+a[i][j]);
		}
		cout<<(l)<<' ';
		if(i != n-1)
			cout<<endl;
	}
		
		
	return 0;
}
